package com.zenith.api.feign.storage;

import com.zenith.common.result.PageResult;
import com.zenith.common.result.Result;
import com.zenith.api.po.dto.storage.*;
import com.zenith.api.po.vo.storage.*;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 存储服务Feign客户端 - API服务
 */
@FeignClient(name = "zenith-middleware-service", path = "/middleware/storage", contextId = "api-storage-client")
public interface StorageServiceFeignClient {
    
    // =========================== 分片上传相关接口 ===========================
    
    @Operation(summary = "初始化分片上传")
    @PostMapping("/initChunkUpload")
    Result<ChunkInitVO> initChunkUpload(@Valid @RequestBody ChunkInitDTO chunkInitDTO);

    /**
     * 上传分片
     */
    @Operation(summary = "上传分片")
    @PostMapping("/chunkUploadService")
    Result<ChunkUploadVO> uploadChunk(@Valid @RequestBody ChunkUploadDTO chunkUploadDTO);

    /**
     * 完成分片上传
     */
    @Operation(summary = "完成分片上传")
    @PostMapping("/completeChunkUpload")
    Result<FileVO> completeChunkUpload(@Valid @RequestBody ChunkCompleteDTO chunkCompleteDTO);

    /**
     * 获取分片上传状态
     */
    @Operation(summary = "获取分片上传状态")
    @PostMapping("/getChunkStatus/{uploadKey}")
    Result<ChunkStatusVO> getChunkStatus(@PathVariable String uploadKey);

    // =========================== 网盘功能相关接口 ===========================
    
    @Operation(summary = "创建文件夹")
    @PostMapping("/createFolder")
    Result<FolderVO> createFolder(@Valid @RequestBody FolderDTO folderDTO);

    /**
     * 获取文件夹树
     */
    @Operation(summary = "获取文件夹树")
    @PostMapping("/getFolderTree")
    Result<List<FolderVO>> getFolderTree(@RequestParam Long userId);

    /**
     * 获取文件夹中的文件列表
     */
    @Operation(summary = "获取文件夹中的文件列表")
    @PostMapping("/getFolderFiles")
    Result<PageResult<FolderFileVO>> getFolderFiles(FolderFileQueryDTO queryDTO);

    /**
     * 移动文件
     */
    @Operation(summary = "移动文件")
    @PostMapping("/moveFile")
    Result<Boolean> moveFile(@Valid @RequestBody MoveFileDTO moveFileDTO);

    /**
     * 重命名文件或文件夹
     */
    @Operation(summary = "重命名文件或文件夹")
    @PostMapping("/rename")
    Result<Boolean> rename(@Valid @RequestBody RenameDTO renameDTO);

    // =========================== 文件管理相关接口 ===========================
    
    @Operation(summary = "初始化上传")
    @PostMapping("/initUpload")
    Result<UploadInitVO> initUpload(@Valid @RequestBody UploadInitDTO uploadInitDTO);

    /**
     * 上传文件
     */
    @Operation(summary = "上传文件")
    @PostMapping("/uploadFile")
    Result<FileVO> uploadFile(@RequestParam("file") MultipartFile file,
                              @RequestParam("fileId") Long fileId);

    /**
     * 下载文件
     */
    @Operation(summary = "下载文件")
    @PostMapping("/downloadFile/{fileId}")
    void downloadFile(@PathVariable Long fileId, HttpServletResponse response);

    /**
     * 删除文件
     */
    @Operation(summary = "删除文件")
    @PostMapping("/deleteFile/{fileId}")
    Result<Boolean> deleteFile(@PathVariable Long fileId);

    /**
     * 获取文件详情
     */
    @Operation(summary = "获取文件详情")
    @PostMapping("/getFileDetail/{fileId}")
    Result<FileVO> getFileDetail(@PathVariable Long fileId);

    /**
     * 分页查询文件列表
     */
    @Operation(summary = "分页查询文件列表")
    @PostMapping("/listFiles")
    Result<PageResult<FileVO>> listFiles(FileQueryDTO queryDTO);

    // =========================== 存储提供商相关接口 ===========================
    
    /**
     * 获取所有存储提供商列表
     */
    @Operation(summary = "获取所有存储提供商列表")
    @PostMapping("/listProviders")
    Result<List<StorageProviderVO>> listProviders();

    /**
     * 添加存储提供商
     */
    @Operation(summary = "添加存储提供商")
    @PostMapping("/addProvider")
    Result<Boolean> addProvider(@Valid @RequestBody ProviderDTO providerDTO);

    /**
     * 更新存储提供商
     */
    @Operation(summary = "更新存储提供商")
    @PostMapping("/updateProvider")
    Result<Boolean> updateProvider(@Valid @RequestBody ProviderDTO providerDTO);

    /**
     * 删除存储提供商
     */
    @Operation(summary = "删除存储提供商")
    @DeleteMapping("/deleteProvider/{id}")
    Result<Boolean> deleteProvider(@PathVariable("id") Long id);

    @Operation(summary = "设置默认存储提供商")
    @PutMapping("/setDefaultProvider/{id}")
    Result<Boolean> setDefaultProvider(@PathVariable("id") Long id);

    /**
     * 获取默认存储提供商
     */
    @Operation(summary = "获取默认存储提供商")
    @PostMapping("/getDefaultProvider")
    Result<StorageProviderVO> getDefaultProvider();
}